package com.hzy.fivepalace.wx.controller.api;

import com.hzy.fivepalace.wx.annotation.LoginUser;
import com.hzy.fivepalace.wx.controller.base.BaseController;
import com.hzy.fivepalace.wx.service.WxCartService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * 用户购物车服务
 */
@RestController
@RequestMapping("/wx/cart")
@Validated
@Api(tags = "用户购物车服务")
public class WxCartController extends BaseController {
    private static final Logger logger = LoggerFactory.getLogger(WxCartController.class);

    @Resource
    private WxCartService cartService;


    /**
     * 更改购物车选中状态
     *
     * @param userId
     * @param body
     * @return
     */
    @PostMapping("/cartCheckStatus")
    @ApiOperation(value = "更改购物车选中状态")
    public Object cartCheckStatus(@LoginUser @ApiParam(hidden = true) Integer userId,
            @ApiParam(value = "{cartIds:[1,2,3],checkStatus:true}") @RequestBody String body) {
        return cartService.cartCheckStatus(userId, body);
    }


    /**
     * 清空购物车
     *
     * @param userId
     * @return
     */
    @PostMapping("/emptyCart")
    @ApiOperation(value = "清空购物车")
    public Object emptyCart(@LoginUser @ApiParam(hidden = true) Integer userId) {
        return cartService.emptyCart(userId);
    }

    /**
     * 购物车数量
     * @param userId
     * @return
     */
    @GetMapping("/getCartCount")
    @ApiOperation(value = "购物车数量")
    public Object getCartCount(@LoginUser(login = false) @ApiParam(hidden = true) Integer userId) {
        return cartService.getCartCount(userId);
    }

    /**
     * 购物车列表
     * @param userId
     * @return
     */
    @GetMapping("/list")
    @ApiOperation(value = "购物车列表")
    public Object getUserCartList(@LoginUser @ApiParam(hidden = true) Integer userId) {
        return cartService.getUserCartList(userId);
    }


    /**
     * 删除购物车
     *
     * @param userId
     * @param body
     * @return
     */
    @PostMapping("/delCart")
    @ApiOperation(value = "删除购物车")
    public Object delCart(@LoginUser @ApiParam(hidden = true) Integer userId,
                          @ApiParam(value = "{cartIds:[1,2,3]}") @RequestBody String body) {
        return cartService.delCart(userId, body);
    }

    /**
     * 加入、减少购物车
     * @param userId
     * @param body
     * @return
     */
    @PostMapping("/addOrReduceCart")
    @ApiOperation(value = "加入、减少购物车")
    public Object addOrReduceCart(@LoginUser @ApiParam(hidden = true) Integer userId,
            @ApiParam(value = "{specificationId:规格id,number:1}") @RequestBody String body) {
        return cartService.addOrReduceCart(userId, body);
    }
}

